#!/usr/bin/env python 2.7
# -*- coding: utf-8 -*-
# @Time      :2021/6/8
# @Author    :zhangxuchuo
# @Email     :zhangxuchuo@bbdservice.com
# @File      :IC105_IndGuarantyConsCnt
# @Software  :PyCharm


'''eof
name:申请人在行内业务对外担保为关注
code:IC105_IndGuarantyConsCnt_FL
tableName:
columnName:
groups:个人征信模块
dependencies:RELATE_GUARANTEE
type:常用指标
datasourceType:在线指标
description:
eof'''

import json
import re
import sys
import datetime
import pandas as pd

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--', []]

def isFloat(x):
    '''
    判断x为float类型且大于等于0
    :param x:
    :return:
    '''
    try:
        if isinstance(float(x), float) and float(x) >= 0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False

def IC107_Ind12MonsContiOvduCnt():
    # RELATE_GUARANTEE = data.get('RELATE_GUARANTEE')
    try:
        num = []
        relates = RELATE_GUARANTEE.get('relate_guarantee', '')
        if relates == '':
            return '缺失值'
        else:
            for i in relates:
                is_inner = i.get('is_inner', '')
                followStatusCount = i.get('followStatusCount', '')
                if is_inner not in null_type_list and isFloat(followStatusCount):
                    if is_inner == 'true' and isFloat(followStatusCount) >= 0:
                        num.append(float(followStatusCount))
                    else:
                        num.append(0)
                else:
                    num.append('None')
        if len(list(set(num))) == 1 and list(set(num))[0] == 'None':
            return '缺失值'
        else:
            num = [i for i in num if i != 'None']
            return sum(num)
    except:
        return '缺失值'

result = IC107_Ind12MonsContiOvduCnt()
